using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class WorkshopButtons3D : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024find_0024419 : GenericGenerator<WaitForSeconds>
	{
		internal WorkshopButtons3D _0024self__0024421;

		public _0024find_0024419(WorkshopButtons3D self_)
		{
			_0024self__0024421 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024421);
		}
	}

	[NonSerialized]
	public static bool fromWorkshop;

	public disableworkshop dis;

	public GameObject topsWork;

	public GameObject topsLoad;

	public Camera textcam;

	public GameObject[] topsL;

	public GameObject[] topsW;

	public GameObject bg;

	private TopSelect topSelect;

	public movelimiter2 limiter;

	[HideInInspector]
	public bool allowed;

	public AudioClip clip;

	public Color pressed;

	public Color unpressed;

	public Collider back;

	public Collider attackring;

	public Collider chip;

	public Collider weightdisk;

	public Collider @base;

	public Collider market;

	public Collider select;

	public Camera mainCamera;

	private ddload ddload;

	public int attackstate;

	public int basestate;

	public int diskstate;

	public int chipstate;

	private setparts partLoader;

	private Transform tr;

	public WorkshopButtons3D()
	{
		allowed = true;
		attackstate = 1;
		basestate = 1;
		diskstate = 1;
		chipstate = 1;
	}

	public void Start()
	{
		tr = transform;
		StartCoroutine(find());
		attackstate = PlayerPrefs.GetInt("AttackState");
		diskstate = PlayerPrefs.GetInt("DiskState");
		basestate = PlayerPrefs.GetInt("BaseState");
		chipstate = PlayerPrefs.GetInt("ChipState");
	}

	private IEnumerator find()
	{
		return new _0024find_0024419(this).GetEnumerator();
	}

	public void Update()
	{
		if (Input.GetMouseButtonUp(0))
		{
			st();
		}
		if (!Input.GetMouseButtonDown(0) || !allowed)
		{
			return;
		}
		RaycastHit hitInfo = default(RaycastHit);
		if (!Physics.Raycast(mainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition), out hitInfo, 100f))
		{
			return;
		}
		if (hitInfo.collider.name == "InfoToggle")
		{
			((SpecialAttackInfo)hitInfo.collider.GetComponent(typeof(SpecialAttackInfo))).ShowInfo();
			return;
		}
		if (hitInfo.collider.name == "Back")
		{
			AudioSource.PlayClipAtPoint(clip, tr.position);
			back.GetComponent<Renderer>().material.color = pressed;
			back.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu2");
		}
		if (hitInfo.collider.name == "AttackRing")
		{
			AudioSource.PlayClipAtPoint(clip, tr.position);
			attackring.GetComponent<Renderer>().material.color = pressed;
			attackring.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			attackstate++;
			attackchange();
			ddload.state = attackstate;
		}
		if (hitInfo.collider.name == "Base")
		{
			AudioSource.PlayClipAtPoint(clip, tr.position);
			@base.GetComponent<Renderer>().material.color = pressed;
			@base.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			basestate++;
			basechange();
			ddload.basestate = basestate;
		}
		if (hitInfo.collider.name == "Chip")
		{
			AudioSource.PlayClipAtPoint(clip, tr.position);
			chip.GetComponent<Renderer>().material.color = pressed;
			chip.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			chipstate++;
			chipchange();
			ddload.chipstate = chipstate;
		}
		if (hitInfo.collider.name == "WeightDisk")
		{
			AudioSource.PlayClipAtPoint(clip, tr.position);
			weightdisk.GetComponent<Renderer>().material.color = pressed;
			weightdisk.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			diskstate++;
			diskchange();
			ddload.diskstate = diskstate;
		}
		if (hitInfo.collider.name == "Market")
		{
			fromWorkshop = true;
			AudioSource.PlayClipAtPoint(clip, tr.position);
			market.GetComponent<Renderer>().material.color = pressed;
			market.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			UnityEngine.SceneManagement.SceneManager.LoadScene("market");
		}
		if (hitInfo.collider.name == "Select")
		{
			AudioSource.PlayClipAtPoint(clip, tr.position);
			select.GetComponent<Renderer>().material.color = pressed;
			select.GetComponent<Renderer>().material.SetColor("_SpecColor", pressed);
			topSelect.allowed = true;
			topsLoad.active = true;
			load();
			allowed = false;
		}
	}

	public void CheckParts()
	{
		partLoader.load(attackstate, diskstate, basestate, chipstate);
	}

	public void attackchange()
	{
		while (PlayerPrefs.GetInt("Attack" + attackstate) != 1)
		{
			attackstate++;
			if (attackstate > topsL.Length)
			{
				attackstate = 1;
			}
		}
		partLoader.load(attackstate, 0, 0, 0);
	}

	public void basechange()
	{
		while (PlayerPrefs.GetInt("Base" + basestate) != 1)
		{
			basestate++;
			if (basestate > topsL.Length)
			{
				basestate = 1;
			}
		}
		partLoader.load(0, 0, basestate, 0);
	}

	public void chipchange()
	{
		while (PlayerPrefs.GetInt("Chip" + chipstate) != 1)
		{
			chipstate++;
			if (chipstate > topsL.Length)
			{
				chipstate = 1;
			}
		}
		partLoader.load(0, 0, 0, chipstate);
	}

	public void diskchange()
	{
		while (PlayerPrefs.GetInt("Disk" + diskstate) != 1)
		{
			diskstate++;
			if (diskstate > topsL.Length)
			{
				diskstate = 1;
			}
		}
		partLoader.load(0, diskstate, 0, 0);
	}

	public void load()
	{
		limiter.mxpos = 0.9f;
		int num = 0;
		for (int i = 0; i < topsL.Length; i++)
		{
			if ((bool)topsL[i])
			{
				if (PlayerPrefs.GetInt("Top" + (i + 1).ToString()) == 1)
				{
					topsL[i].SetActiveRecursively(state: true);
					float x = (float)num * 4.5f;
					Vector3 localPosition = topsL[i].transform.localPosition;
					localPosition.x = x;
					Vector3 vector2 = topsL[i].transform.localPosition = localPosition;
					topsL[i].GetComponent<Collider>().enabled = false;
					topsL[i].GetComponent<Collider>().enabled = true;
					limiter.mxpos -= 0.9f;
					num++;
				}
				else
				{
					topsL[i].GetComponent<Collider>().enabled = false;
					topsL[i].SetActiveRecursively(state: false);
				}
			}
		}
		int num2 = 0;
		Vector3 position = topsLoad.transform.position;
		position.x = num2;
		Vector3 vector4 = topsLoad.transform.position = position;
		bg.SetActiveRecursively(state: true);
		topsWork.SetActiveRecursively(state: false);
		StartCoroutine(dis.dis());
	}

	public void st()
	{
		back.GetComponent<Renderer>().material.color = unpressed;
		attackring.GetComponent<Renderer>().material.color = unpressed;
		@base.GetComponent<Renderer>().material.color = unpressed;
		chip.GetComponent<Renderer>().material.color = unpressed;
		weightdisk.GetComponent<Renderer>().material.color = unpressed;
		market.GetComponent<Renderer>().material.color = unpressed;
		select.GetComponent<Renderer>().material.color = unpressed;
		back.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
		attackring.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
		@base.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
		chip.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
		weightdisk.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
		market.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
		select.GetComponent<Renderer>().material.SetColor("_SpecColor", Color.white);
	}

	public void Main()
	{
	}
}
